import {
    Column,
    CreateDateColumn,
    Entity,
    JoinTable,
    ManyToMany,
    PrimaryGeneratedColumn,
    UpdateDateColumn,
} from 'typeorm';

import { RoleEntity } from './role.entity';
import { Exclude, Expose } from 'class-transformer';
import { ApiHideProperty } from '@nestjs/swagger';
@Entity({
    name: 'users',
})
@Exclude()
export class UserEntity {
    @Expose()
    @PrimaryGeneratedColumn()
    id: number;

    @Expose()
    @Column({
        length: 50,
        comment: '用户名',
    })
    username: string;

    @ApiHideProperty()
    @Expose({ groups: ['user-updatePassword'] })
    @Column({
        length: 50,
        comment: '密码',
    })
    password: string;

    @Expose()
    @Column({
        name: 'nickname',
        length: 50,
        comment: '昵称',
    })
    nickname: string;

    @Expose()
    @Column({
        length: 50,
        comment: '邮箱',
    })
    email: string;

    @Expose()
    @Column({
        length: 200,
        comment: '头像',
        nullable: true,
    })
    headPic?: string;

    @Expose()
    @Column({
        comment: '手机号',
        length: 20,
        nullable: true,
    })
    phoneNumber: string;

    @Expose()
    @Column({
        comment: '是否冻结',
        default: false,
    })
    isFrozen?: boolean;

    @Expose()
    @Column({
        comment: '是否是管理员',
        default: false,
    })
    isAdmin?: boolean;
    @Expose()
    @CreateDateColumn({ comment: '创建时间' })
    createTime: Date;

    @UpdateDateColumn({ comment: '更新时间' })
    updateTime: Date;

    @Expose()
    @ManyToMany(() => RoleEntity)
    @JoinTable({
        name: 'user_roles',
    })
    roles: RoleEntity[];
}
